package xpn.platform.modules.login;

import java.util.Set;

import xpn.platform.modules.sys.org.SysOrg;
import xpn.platform.modules.sys.user.SysUser;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 登录成功信息
 *
 * @author bobatkm
 *
 */
@Data
public class LoginOkDTO {

	@JsonIgnore
	private SysUser sysUser; // 用户对象

	private Token token; // Token信息
	private Set<String> permissions; // 用户权限信息
	private User user; // 用户信息

	public LoginOkDTO(SysUser sysUser, Token token, Set<String> permissions) {
		this.setSysUser(sysUser);
		this.setToken(token);
		this.setPermissions(permissions);

		this.user = new User();
		user.setId(sysUser.getId());
		user.setName(sysUser.getName());
		user.setMobile(sysUser.getMobile());
		user.setOrg(sysUser.getOrg());
		user.setRoleList(sysUser.fetchRoleList());
		user.setUserCode(sysUser.getUserCode());
		user.setUserName(sysUser.getUserName());
		user.setOrgFullName(sysUser.fetchOrgFullName());
	}

	@Data
	@AllArgsConstructor
	public static class Token {
		private String name;
		private String value;
	}

	@Data
	public static class User {
		Long id;
		String userName;
		String userCode;
		String name;
		String mobile;
		String orgFullName;

		SysOrg org;
		Set<String> roleList;

		String selfLink;
	}
}
